<template>
	<view class="set_split_container">
		<view class="set_split_box">
			<view class="set_split_all">
				<view class="split_img_box">
					<image :src="topImg" mode="" class="split_img"></image>
				</view>

				<view class="split_details_box">
					<u-radio-group v-model="percentageObj.default_yj_type" @change="handleChangeRadioGroup"
						class="radio_label">
						<u-radio v-for="(item, index) in typeList" :key="item.id" :name="item.id" class="radio_header"
							x>
							{{ item.name }}
						</u-radio>
					</u-radio-group>
					<view class="">
						<view class="radio_input_box">
							<view class="radio_input">
								<u-input v-model="percentageObj.default_yj_p" :clearable="false" :border="false"
									placeholder="请输入抽成比例"
									placeholder-style="font-family: Source Han Sans CN;font-weight: 400;font-size: 24rpx;color: #808080;" />
							</view>
							<view class="">
								%
							</view>
						</view>
						<view class="radio_input_box">
							<view class="radio_input">
								<u-input v-model="percentageObj.default_yj_a" :clearable="false" :border="false"
									placeholder="请输入抽成金额"
									placeholder-style="font-family: Source Han Sans CN;font-weight: 400;font-size: 24rpx;color: #808080;" />
							</view>
							<view class="">
								元
							</view>
						</view>
					</view>
				</view>
			</view>

			<view class="split_btn_box">
				<view class="split_btn" @click="handleGenerate">
					生成招募邀请码
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				yjType: '',
				topImg: 'https://file-1314054542.cos.ap-shanghai.myqcloud.com/cos_file/wechat_xcx/668ddf8b2f63a_1720573835.png',
				typeList: [{
						id: 1,
						name: "抽成比例",
					},
					{
						id: 2,
						name: "抽成金额",
					},
				],
				percentageObj: {
					default_yj_type: '',
					default_yj_a: '', // 金额输入框的值
					default_yj_p: '' // 比例输入框的值
				},
				userIsAgent: uni.getStorageSync('h5-isAgent')
			}
		},
		onLoad() {
			this.getAgentLoginInfo()
		},
		methods: {
			// 获取登录合伙人信息接口
			getAgentLoginInfo() {
				const url = uni.getStorageSync('h5-isAgent') == 0 ? '/api/getFxuserLoginInfo' : '/api/getAgentLoginInfo'
				this.$request(url, {}, 'GET').then(res => {
					if (res.code == 1) {
						this.percentageObj = res.data
					} else {
						uni.showToast({
							title: '查询用户信息失败',
							icon: 'none'
						})
						return
					}
				})
			},

			// 设置用户默认分成接口
			setUserDefaultYj() {
				this.$request('/api/setUserDefaultYj', {
					default_yj_type: this.percentageObj.default_yj_type,
					default_yj_p: this.percentageObj.default_yj_p,
					default_yj_a: this.percentageObj.default_yj_a,
				}, 'POST').then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: this.percentageObj.default_yj_type == 1 ? '设置抽成比例成功' : '设置抽成金额成功',
							icon: 'none'
						})
						if (this.userIsAgent == 0) {
							// 分销员
							// 调分享员招募
							uni.navigateTo({
								url: '/pages/my/distributorsPromote/distributorsPromote'
							})
						} else {
							// 合伙人
							// 调分享员招募
							uni.navigateTo({
								url: '/pages/agentPortion/my/distributorsPromote/distributorsPromote'
							})
						}
					} else {
						uni.showToast({
							title: this.percentageObj.default_yj_type == 1 ? '设置抽成比例失败' : '设置抽成金额失败',
							icon: 'none'
						})
					}
				})
			},

			// 选择分销类型
			handleChangeRadioGroup(e) {
			},

			// 生成招募邀请码
			handleGenerate() {
				if (this.percentageObj.default_yj_type == 0) {
					uni.showToast({
						title: '请设置抽成类型',
						icon: 'none'
					})
					return
				}

				this.setUserDefaultYj()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.set_split_container {
		padding: 20rpx 18rpx 0;

		.set_split_box {
			background: #FFFFFF;
			box-shadow: 0px 8rpx 10rpx 1px rgba(213, 213, 213, 0.14);
			border-radius: 20rpx;
			border: 2rpx solid #FFFFFF;
			padding: 20rpx 20rpx 29rpx;

			.set_split_all {
				display: flex;
				justify-content: space-between;
				background: #FFFFFF;
				box-shadow: 0px 7rpx 5rpx 0px rgba(14, 37, 91, 0.13);
				border-radius: 14rpx;
				border: 1px solid #000000;
				padding-right: 23rpx;

				.split_img_box {
					width: 174rpx;
					height: 192rpx;

					.split_img {
						width: 100%;
						height: 100%;
					}
				}

				.split_details_box {
					display: flex;
					align-items: baseline;
					padding-top: 27rpx;

					.radio_label {

						.radio_header {
							display: flex;
							flex-direction: column;
							margin-bottom: 25rpx;
						}
					}

					.radio_input_box {
						display: flex;
						align-items: center;
						margin-bottom: 25rpx;

						.radio_input {
							width: 213rpx;
							height: 59rpx;
							background: #FAFAFA;
							border-radius: 12rpx;
							border: 1px solid #EBEBEB;
							margin-right: 10rpx;
						}
					}
				}
			}

			.split_btn_box {

				.split_btn {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 666rpx;
					height: 79rpx;
					background: #0E255B;
					border-radius: 14rpx;
					font-family: Source Han Sans CN;
					font-weight: 500;
					font-size: 30rpx;
					color: #FFD79A;
				}
			}

			/* 当屏幕宽度小于或等于600px时（小屏幕手机），设置新的高度 */
			@media (max-width: 600px) {
				.split_btn_box {
					margin-top: 70vh;
				}
			}

			/* 当屏幕宽度在601px到900px之间时（中等屏幕手机或平板），设置另一个高度 */
			@media (min-width: 601px) and (max-width: 900px) {
				.split_btn_box {
					margin-top: 500rpx;
					/* 中等屏幕的高度 */
				}
			}

			/* 当屏幕宽度大于900px时（大屏幕设备），可以选择设置或不设置高度，这里为了示例也设置一个高度 */
			@media (min-width: 901px) {
				.split_btn_box {
					margin-top: 600rpx;
					/* 大屏幕的高度 */
				}
			}
		}
	}
</style>